/**
 * Created by tingwang on 2017/7/20.
 */
odoo.define('product_url.widget_url', function (require) {
    "use strict";
    var core = require('web.core');
    var list_widget_registry = core.list_widget_registry;
    var _t = core._t;
    var Column = list_widget_registry.get('field');
    var Column_Product_Url = Column.extend({
        PROTOCOL_REGEX: /^(?!\w+:?\/\/)/,
        _format: function (row_data, options) {
            var value = row_data[this.id].value;
            if (value) {
                return _.template("<a href='<%-href%>' target='_blank'><%-text%></a>")({
                    href: value.trim().replace(this.PROTOCOL_REGEX, '//'),
                    text: _t("Link")
                });
            }
            return this._super(row_data, options);
        }
    });
    list_widget_registry.add('field.product_url', Column_Product_Url);
});